package com.ljm.sys.auth.controller;

import com.ljm.common.dto.BaseResult;
import com.ljm.common.util.ResultUtil;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
import com.ljm.sys.auth.api.SysAuthResourceApi;
import com.ljm.sys.auth.dto.SysAuthResourceDto;

import org.springframework.stereotype.Controller;

/**
 * <p>
    * 系统资源 前端控制器
    * </p>
 *
 * @author HuamingChen
 * @since 2020-06-11
 */
@Api("系统资源")
@RestController
@RequestMapping("/auth/sysAuthResource")
public class SysAuthResourceController {

    /**
    * 系统资源接口
    */
    @Resource
    private SysAuthResourceApi iSysAuthResourceApi;

    @ApiOperation(value="保存系统资源")
    @RequestMapping(value = "/save",method = RequestMethod.POST)
    public BaseResult save(@ApiParam(value="系统资源") @RequestBody @Validated SysAuthResourceDto dto){
        iSysAuthResourceApi.saveData(dto);
        return ResultUtil.success();
    }

    @ApiOperation(value="删除系统资源")
    @RequestMapping(value = "/del",method = RequestMethod.GET)
    public BaseResult del(@ApiParam(value="主键") @RequestParam Long id){
        iSysAuthResourceApi.delData(id);
        return ResultUtil.success();
    }

    @ApiOperation(value="获取系统资源")
    @RequestMapping(value = "/getById",method = RequestMethod.GET)
    public BaseResult getById(@ApiParam(value="主键") @RequestParam Long id){
        return ResultUtil.successData(iSysAuthResourceApi.getDataById(id));
    }

    @ApiOperation(value="分页获取系统资源")
    @RequestMapping(value = "/getByPage",method = RequestMethod.GET)
    public BaseResult getByPage(@ApiParam(value="资源名称") @RequestParam(required = false) String resName,
                                @ApiParam(value="权限代码") @RequestParam(required = false) String permissionCode,
                                @ApiParam(value="资源路径") @RequestParam(required = false) String resPath,
                                @ApiParam(value="资源全路径") @RequestParam(required = false) String resFullPath,
                                @ApiParam(value="页码") @RequestParam(required = false) Integer pageNo,
                                @ApiParam(value="页大小") @RequestParam(defaultValue = "10") Integer pageSize){
        SysAuthResourceDto dto=new SysAuthResourceDto(resName,permissionCode,resPath,resFullPath,pageNo,pageSize);
        return ResultUtil.successData(iSysAuthResourceApi.getDataByPage(dto));
    }

    @ApiOperation(value="获取所有系统资源")
    @RequestMapping(value = "/getAllResource",method = RequestMethod.GET)
    public BaseResult getAllResource(){
        return ResultUtil.successData(iSysAuthResourceApi.getAllRes());
    }

    @ApiOperation(value="获取子资源")
    @RequestMapping(value = "/getChlildRes",method = RequestMethod.GET)
    public BaseResult getChlildRes(@ApiParam(value="上级id") @RequestParam(required = true) Long parentId){
        return ResultUtil.successData(iSysAuthResourceApi.getChlildRes(parentId));
    }
}
